import javax.script.*;
import java.util.List;

public class Test {
    public static void main(String[] args) throws ScriptException, NoSuchMethodException {
        ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
        ScriptEngine engine = scriptEngineManager.getEngineByName("nashorn");
        List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
        engineFactories.forEach(t->{
            System.out.println("t.getEngineName() = " + t.getEngineName());
        });
        Tech tech = new Tech(166L, "工字钢", "ibeam==true", false, false, null);
        Rebar rebar = new Rebar();
        rebar.setMaterialType("i_beam");
        //调用脚本
        String script = "var func = function(rebar){ var t = {}; Object.bindProperties(t,rebar); with(t){ return " + tech.getRule() + "; } }";
        engine.eval(script);
        System.out.println("script: " + script);
        System.out.println("rebar = " + rebar);
        System.out.println("===============================");
        Object result = ((Invocable) engine).invokeFunction("func", rebar);
        System.out.println("result = " + result);
    }
}
